package cn.source.web.controller.gygl;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.source.system.domain.Bill;
import cn.source.system.service.IBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.Room;
import cn.source.system.service.IRoomService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;
/**
 * 房间管理Controller
 *
 * @author gygl
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/room")
@Api(value = "/room", description = "Operations about room")
public class RoomController extends BaseController {
    @Autowired
    private IRoomService roomService;
    @Autowired
    private IBillService billService;
    /**
     * 查询房间管理列表
     */
    // @PreAuthorize("@ss.hasPermi('system:room:list')")
    @ApiOperation("查询房间管理列表")
    @GetMapping("/list")
    public TableDataInfo list(Room room) {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }
    /**
     * 导出房间管理列表
     */
    // @PreAuthorize("@ss.hasPermi('system:room:export')")
    @ApiOperation("出房间管理列表")
    @Log(title = "房间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Room room) {
        List<Room> list = roomService.selectRoomList(room);
        ExcelUtil<Room> util = new ExcelUtil<Room>(Room.class);
        util.exportExcel(response, list, "房间管理数据");
    }
    /**
     * 获取房间管理详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:room:query')")
    @ApiOperation("获取房间管理详细信息")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId) {
        return AjaxResult.success(roomService.selectRoomByRoomId(roomId));
    }
    /**
     * 新增房间管理
     */
    //  @PreAuthorize("@ss.hasPermi('system:room:add')")
    @ApiOperation("新增房间管理")
    @Log(title = "房间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Room room) {
        return toAjax(roomService.insertRoom(room));
    }
    /**
     * 修改房间管理
     */
    // @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @ApiOperation("修改房间管理")
    @Log(title = "房间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Room room) {
        return toAjax(roomService.updateRoom(room));
    }
    /**
     * 删除房间管理
     */
    // @PreAuthorize("@ss.hasPermi('system:room:remove')")
    @ApiOperation("删除房间管理")
    @Log(title = "房间管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds) {
        return toAjax(roomService.deleteRoomByRoomIds(roomIds));
    }
    /**
     * 查询所有房间的空余床位
     */
    @ApiOperation("查询所有房间的空余床位")
    @GetMapping("/available")
    public AjaxResult available(Room room, Bill bill) {
        int o = (int) roomService.selectRoomAllList(room);
        int o1 = (int) billService.selectCheckInRoomCount(bill);
        int o2 = (int) billService.selectCheckOutRoomCount(bill);
        int available = o - o1 - o2;
        return AjaxResult.success(available);
    }
    /**
     * 查询所有房间的所有床位
     */
    @ApiOperation("查询所有房间的所有床位")
    @GetMapping("/allrooms")
    public AjaxResult allrooms(Room room) {
        return AjaxResult.success(roomService.selectRoomAllList(room));
    }
    /**
     * 查询入住人数
     */
    @ApiOperation("查询入住人数")
    @GetMapping("/checkInAll")
    public AjaxResult checkInAll(Bill bill) {
        return AjaxResult.success(billService.selectCheckInRoomCount(bill));
    }
    /**
     * 查询预约人数
     */
    @ApiOperation("查询预约人数")
    @GetMapping("/checkOutAll")
    public AjaxResult checkOutAll(Bill bill) {
        return AjaxResult.success(billService.selectCheckOutRoomCount(bill));
    }
    /**
     * 获取房间详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('system:room:query')")
    @ApiOperation("获取房间管理详细信息")
    @GetMapping(value = "/get/{roomNo}")
    public AjaxResult getRoom(@PathVariable("roomNo") Long roomNo) {
        return AjaxResult.success(roomService.selectGetRoomByRoomNo(roomNo));
    }
    /**
     * 根据楼层获取房间信息
     *
     * @param roomFloor
     * @return
     */
    @ApiOperation("根据楼层获取房间信息")
    @GetMapping("/roomFloor/{roomFloor}")
    public AjaxResult getRoomFloor(@PathVariable("roomFloor") String roomFloor){
        return AjaxResult.success(roomService.getRoomFloor(roomFloor));
    }
    @ApiOperation("获取房间详情——连表")
    @GetMapping("/getRoom/{roomNo}")
    public AjaxResult getRoomInfo(@PathVariable("roomNo") String roomNo){
        return AjaxResult.success(roomService.getRoomInfo(roomNo));
    }
    /**
     * 获取所有房间号
     */
    @ApiOperation("获取所有房间号")
    @GetMapping("/getAllRoomNo")
    public AjaxResult getAllRoomNo(Room room) {
        return AjaxResult.success(roomService.getAllRoomNo(room));
    }
}
